package com.cxb.serviceprice.controller;


import com.cxb.internalcommon.dto.PriceRule;
import com.cxb.internalcommon.dto.ResponseResult;
import com.cxb.internalcommon.request.PriceRuleIsNewRequest;
import com.cxb.serviceprice.service.PriceRuleService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陈晓波
 * @since 2024-08-08
 */
@RestController
@RequestMapping("/price-rule")
public class PriceRuleController {

    @Autowired
    private PriceRuleService priceRuleService;

    /**
     * 添加计价规则
     * @param priceRule
     * @return
     */
    @PostMapping("/add")
    public ResponseResult add(@RequestBody PriceRule priceRule){

        return priceRuleService.add(priceRule);
    }

    /**
     * 编辑计价规则
     * @param priceRule
     * @return
     */
    @PostMapping("/edit")
    public ResponseResult edit(@RequestBody PriceRule priceRule){
        return priceRuleService.edit(priceRule);
    }


    /**
     * 查询计价规则
     * @param fareType
     * @return
     */
    @GetMapping("/get-newest-version")
    public ResponseResult<PriceRule> getNewVersion(@RequestParam String fareType){

        return priceRuleService.getNewVersion(fareType);
    }

    /**
     * 是否是最新计价规则
     * @param priceRuleIsNewRequest
     * @return
     */
    @PostMapping("/is-newest")
    public ResponseResult<Boolean> isNew(@RequestBody PriceRuleIsNewRequest priceRuleIsNewRequest){

        String fareType = priceRuleIsNewRequest.getFareType();
        Integer fareVersion = priceRuleIsNewRequest.getFareVersion();
        return priceRuleService.isNew(fareType,fareVersion);
    }

    /**
     * 根据城市编码和对应车型查询计价规则是否存在
     * @param priceRule
     * @return
     */
    @PostMapping("/if-exists")
    public ResponseResult<Boolean> ifExists(@RequestBody PriceRule priceRule){
        return priceRuleService.ifExists(priceRule);
    }

}
